<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			window.onload = function(){
				//修改每个th,td的颜色
				var node = document.getElementsByTagName("th")[0];
				node.style.background = "dodgerblue";
				var node2 = document.getElementsByTagName("th")[1];
				node2.style.background = "red";
				var node3 = document.getElementsByTagName("th")[2];
				node3.style.background = "yellow";
				var node4 = document.getElementsByTagName("th")[3];
				node4.style.background = "greenyellow";
				var node5 = document.getElementsByTagName("th")[4];
				node5.style.background = "goldenrod";
				
				//单行为蓝色,偶行为红色
				var oldTable = document.getElementsByTagName("table")[0];
				
				var newTr = document.createElement("tr");
				var newTr2 = document.createElement("tr");
				var text=document.createTextNode("Hello");
				var text2=document.createTextNode("Hello");
				var text3=document.createTextNode("Hello");
				var text4=document.createTextNode("Hello");
				var text5=document.createTextNode("Hello");
				var text6=document.createTextNode("Hello");
				var text7=document.createTextNode("Hello");
				var text8=document.createTextNode("Hello");
				var text9=document.createTextNode("Hello");
				var text10=document.createTextNode("Hello");
				
				var newTd = document.createElement("td");
				var newTd2 = document.createElement("td");
				var newTd3 = document.createElement("td");
				var newTd4 = document.createElement("td");
				var newTd5 = document.createElement("td");
				var newTd6 = document.createElement("td");
				var newTd7= document.createElement("td");
				var newTd8 = document.createElement("td");
				var newTd9 = document.createElement("td");
				var newTd10 = document.createElement("td");
				newTd.appendChild(text);
				newTd2.appendChild(text2);
				newTd3.appendChild(text3);
				newTd4.appendChild(text4);
				newTd5.appendChild(text5);
				newTd6.appendChild(text6);
				newTd7.appendChild(text7);
				newTd8.appendChild(text8);
				newTd9.appendChild(text9);
				newTd10.appendChild(text10);
				
				newTr.appendChild(newTd);
				newTr.appendChild(newTd2);
				newTr.appendChild(newTd3);
				newTr.appendChild(newTd4);
				newTr.appendChild(newTd5);
				
				newTr2.appendChild(newTd6);
				newTr2.appendChild(newTd7);
				newTr2.appendChild(newTd8);
				newTr2.appendChild(newTd9);
				newTr2.appendChild(newTd10);
				
				oldTable.appendChild(newTr);
				oldTable.appendChild(newTr2);
				
				for (var i=0;i<10;i++) {
					var Node=document.getElementsByTagName("tr")[i]
					if (i%2!=0) {
						Node.style.background="red";
					} else{
						Node.style.background="blue";
					}
				}
				console.log(document.getElementsByTagName("td"));
			}
		</script>
	</head>
	<body>
		<table border="1">
				<tr>
					<th class="" >部门名称</th>
					<th class="">部门电话</th>
					<th class="">部门负责人</th>
					<th class="">所属单位</th>
					<th class="">操作</th>
				</tr>
		</table>
	</body>
</html>
